// declare panel data
encode (id), gen (city)
drop id
xtset city year

// data format transformation for statistical modeling
destring business, gen (businesses) force
destring highregulation, gen (highregulations) force
tab year, gen (yeardummy)

// distinguishing the local ruling party shift types: intrapartyshift, interpartyshift
tab headpartychange, gen (headpartyshift)
rename headpartyshift1 noshift
rename headpartyshift2 intrapartyshift
rename headpartyshift3 interpartyshift

// log
generate logbusinesses=ln(businesses)
generate logdensity=ln(density)
generate loggrdp=ln(grdp)
generate logpercapitagrdp=ln(percapitagrdp)

// filling the NAs of opening variable
recode opening (mis=0), gen (opening2)
replace opening2 = opening2[_n+1] if year < 2011
rename opening x
rename opening2 opening
drop x

// testing for hypotheses 1 and 3
xtreg overall headshift majorityshift headmajority opening logbusinesses logdensity loggrdp selfautonomyrate yeardummy1 yeardummy2 yeardummy3 yeardummy4 yeardummy5 yeardummy6 yeardummy7 yeardummy8, fe
xtreg external headshift majorityshift headmajority opening logbusinesses logdensity loggrdp selfautonomyrate yeardummy1 yeardummy2 yeardummy3 yeardummy4 yeardummy5 yeardummy6 yeardummy7 yeardummy8, fe
xtreg internal headshift majorityshift headmajority opening logbusinesses logdensity loggrdp selfautonomyrate yeardummy1 yeardummy2 yeardummy3 yeardummy4 yeardummy5 yeardummy6 yeardummy7 yeardummy8, fe


// procedure for measruing descriptive statistics
xtreg overall headshift majorityshift headmajority opening businesses density grdp selfautonomyrate yeardummy1 yeardummy2 yeardummy3 yeardummy4 yeardummy5 yeardummy6 yeardummy7 yeardummy8, fe
xtreg external headshift majorityshift headmajority opening businesses density grdp selfautonomyrate yeardummy1 yeardummy2 yeardummy3 yeardummy4 yeardummy5 yeardummy6 yeardummy7 yeardummy8, fe
xtreg internal headshift majorityshift headmajority opening businesses density grdp selfautonomyrate yeardummy1 yeardummy2 yeardummy3 yeardummy4 yeardummy5 yeardummy6 yeardummy7 yeardummy8, fe
gen sam = e(sample)
sum overall external internal if sam==1
sum headshift headpartychange majorityshift if sam==1
sum headmajority opening logbusinesses logdensity loggrdp selfautonomyrate if sam==1
tab headshift if sam==1
tab majorityshift if sam==1
pwcorr overall external internal if sam==1, star(.001)
pwcorr internal headshift headpartychange majorityshift density if sam==1, star(.05)

// testing for hypothesis 2
xtreg overall interpartyshift intrapartyshift noshift majorityshift headmajority opening logbusinesses logdensity loggrdp selfautonomyrate yeardummy1 yeardummy2 yeardummy3 yeardummy4 yeardummy5 yeardummy6 yeardummy7 yeardummy8, fe
test interpartyshift = intrapartyshift
xtreg external interpartyshift intrapartyshift noshift majorityshift headmajority opening logbusinesses logdensity loggrdp selfautonomyrate yeardummy1 yeardummy2 yeardummy3 yeardummy4 yeardummy5 yeardummy6 yeardummy7 yeardummy8, fe
test interpartyshift = intrapartyshift
xtreg internal interpartyshift intrapartyshift noshift majorityshift headmajority opening logbusinesses logdensity loggrdp selfautonomyrate yeardummy1 yeardummy2 yeardummy3 yeardummy4 yeardummy5 yeardummy6 yeardummy7 yeardummy8, fe
test interpartyshift = intrapartyshift

// procedure for descriptive statistics of the variables intrapartyshift & interpartyshift
gen sam2 = e(sample)
sum interpartyshift intrapartyshift if sam2==1
tab interpartyshift if sam2==1
tab intrapartyshift if sam2==1


